package pl.ptemich.tankwars;

import java.awt.Dimension;
import java.awt.Toolkit;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import pl.ptemich.tankwars.states.BattleshipsState;
import pl.ptemich.tankwars.states.JBoxTestState;
import pl.ptemich.tankwars.states.MenuState;
import pl.ptemich.tankwars.states.PinballState;
import pl.ptemich.tankwars.states.PlayState;
import pl.ptemich.tankwars.states.RegisteredState;
import pl.ptemich.tankwars.tools.LoggingTools;
import pl.ptemich.tankwars.tools.ScreenTools;
import pl.ptemich.tankwars.tools.StateTools;

/**
 * @author AIPT
 * 
 */
public class TWLGame extends StateBasedGame {
  
  private ScreenTools screenTools;

  public TWLGame(int width, int height) {
    super("Tank Wars Lite");
    this.screenTools = new ScreenTools(width, height, 
                                       GraphicConstants.SCENE_WIDTH,
                                       GraphicConstants.SCENE_HEIGHT);
  }

  @Override
  public void initStatesList(GameContainer arg0) throws SlickException {
    LoggingTools.debug("init states");
    MenuState menu = new MenuState();
    addState(menu);
    
//    RegisteredState state = new HexWarState();
//    menu.addPosition(state);
//    addState(state);       
    
    RegisteredState state = new PinballState();
    menu.addPosition(state);
    addState(state);
    
    state = new BattleshipsState();
    menu.addPosition(state);
    addState(state);
            
    state = new PlayState();
    menu.addPosition(state);
    addState(state);
    
    state = new JBoxTestState();
    menu.addPosition(state);
    addState(state); 
  }

  /**
   * @param args
   */
  public static void main(String[] args) {
    AppGameContainer container;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    try {
      TWLGame instance = new TWLGame(Double.valueOf(screenSize.getWidth()).intValue(), 
                                     Double.valueOf(screenSize.getHeight()).intValue());
      StateTools.registerGame(instance);
      container = new AppGameContainer(instance, Double.valueOf(screenSize.getWidth()).intValue(), 
                                                 Double.valueOf(screenSize.getHeight()).intValue(),
                                                 GraphicConstants.FULL_SCREEN_ENABLED);
      container.setShowFPS(true);
      container.setTargetFrameRate(75);
      //container.setMouseGrabbed(true); // disable mouse cursor
      container.setVSync(true);
      container.start();
    } catch (SlickException e) {
      LoggingTools.error("application init failure");
    }

    LoggingTools.debug("Application end");
  }

  public ScreenTools getScreenTools() {
    return screenTools;
  }
  
}
